<?php


namespace app\shop\controller;


use app\admin\controller\ApiCommon;
use app\common\traits\ActionRecordTrait;
use think\response\Json;

/**
 * Class Log
 * @package app\shop\controller
 * @author Mr.Li
 * @create 2021-06-05 11:34
 */
class Log extends ApiCommon
{

    use ActionRecordTrait;
    /**
     * 用于判断权限
     * @permission 无限制
     * @allow 登录用户可访问
     * @author Mr.Li
     * @create 2021-05-26 16:20
     */
    public function initialize()
    {

        $action = [
            'permission' => [''],
            'allow' => ['index'
            ]
        ];
        event('CheckAuth', $action);
        $request = $this->request;
        $a       = strtolower($request->action());
        if (!in_array($a, $action['permission'])) {
            parent::initialize();
        }
    }


    /**
     * 日志列表
     * @return Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * @author Mr.Li
     * @create 2021-06-05 11:35
     */
    public function index(): Json
    {

        $goodId = $this->param['id'] ?? 0;
        $controller = $this->param['controller'] ?? 'goods';
        $page = $this->param['page'] ?? 1;
        $limit = $this->param['limit'] ?? 20;
        if(!$page){
            $page = 1;
        }
        $data = [];
        $total = 0;
        if($goodId){
            $total = $this->getActionRecordTotal($goodId,'shop',$controller);
            $data = $this->getActionRecordList($goodId,'shop',$controller,'',$page,$limit);
        }
        return resultArray(['data' => ['list' => $data,'dataCount' => $total ]]);
    }

}
